//package com.example.demo;
//
//import org.apache.flink.api.common.restartstrategy.RestartStrategies;
//import org.apache.flink.api.common.time.Time;
//import org.apache.flink.api.common.typeinfo.Types;
//import org.apache.flink.api.java.ExecutionEnvironment;
//import org.apache.flink.api.java.operators.AggregateOperator;
//import org.apache.flink.api.java.operators.DataSource;
//import org.apache.flink.api.java.operators.FlatMapOperator;
//import org.apache.flink.api.java.operators.UnsortedGrouping;
//import org.apache.flink.api.java.tuple.Tuple2;
//import org.apache.flink.streaming.api.datastream.DataStreamSource;
//import org.apache.flink.streaming.api.datastream.KeyedStream;
//import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
//import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
//import org.apache.flink.util.Collector;
//import org.springframework.boot.CommandLineRunner;
//import org.springframework.stereotype.Component;
//
//import java.util.concurrent.TimeUnit;
//
//@Component
//public class StreamWordsCount {
////    public static void main(String[] args) throws Exception {
////
////
////    }
//
//    public static void main(String[] args) throws Exception {
//        DemoApplication.main(args);
//        //创建流式执行环境
//        StreamExecutionEnvironment executionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment();
//        executionEnvironment.setRestartStrategy(RestartStrategies.fixedDelayRestart(
//                3, // 尝试重启的次数
//                Time.of(10, TimeUnit.SECONDS) // 间隔
//        ));
//        //读取文件
//        DataStreamSource<String> stringDataStreamSource = executionEnvironment.readTextFile("demo.txt");
////        DataStreamSource<String> stringDataStreamSource = executionEnvironment.socketTextStream("localhost", 9999);
//
//
//        SingleOutputStreamOperator<Tuple2<String, Long>> returns = stringDataStreamSource.flatMap((String line, Collector<Tuple2<String, Long>> out) -> {
//            String[] words = line.split(" ");
//            for (String word : words) {
//                out.collect(Tuple2.of(word, 1L));
//            }
//        }).returns(Types.TUPLE(Types.STRING, Types.LONG));
//
//        KeyedStream<Tuple2<String, Long>, String> tuple2StringKeyedStream = returns.keyBy(data -> data.f0);
//
//        //求和操作
//        SingleOutputStreamOperator<Tuple2<String, Long>> sum = tuple2StringKeyedStream.sum(1);
//
//        //输出
//        sum.print();
//
//        //每次有数据进行 都会进行输出
//        executionEnvironment.execute();
//
//    }
//}
